<?php 
require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
	MYDCONN();
	$MDARTICLE = 'RD';
	$GLOBALS['MYT'] = $GLOBALS['MYD'];
	if (!isset($GET[1]['Ref'])) {$GET[1]['Ref'] = $_GET['id']; } 
	if ($GET[1]['Ref'] == 0) {$MDARTICLE = 'ED';}  ?>
<table width="97%"  border="0" align="center" cellpadding="2" cellspacing="1" style="color:#000">
      <tr bgcolor="#FFFFFF">
        <td><div align="center">CÓdigo</div></td>
        <td><div align="center">Tipo</div></td>
        <td width="50%"><div align="center">Artigo</div></td>
        <td><div align="center">Quant.</div></td>
        <td><div align="center">Uso</div></td>
        <td>Finalidade</td>
        <td><div align="center"></div></td>
      </tr>
	<?php if($GET[1]['Ref'] == 0) { 
      echo '<tr bgcolor="#E9ECED">
        <td><input name="REFER" type="text" size="8"></td>
        <td>';
		mn_field('hselect','ED','TYPE','',"Produto;Servico;Outros#1;2;3",'','','');
		echo '</td><td>';
		mn_field('hidden',$MDARTICLE,'Article','0',"SELECT Ref, Description FROM ccenter_econ",'','','');
		mn_field('text',$MDARTICLE,'ArticleDescription','','200','50','','');
		mn_field('hidden',$MDARTICLE,'ArticleID','','','','','');
		mn_field('hidden',$MDARTICLE,'ArticleStatus','','','','','');
		mn_field('hidden',$MDARTICLE,'ArticleQuant','','','','','');
		mn_field('hidden',$MDARTICLE,'ArticleDescr','','','','','');
		mn_field('hidden',$MDARTICLE,'ArticleUse','','','','','');
		mn_field('hidden',$MDARTICLE,'ArticleUseTYPE','','','','','');
		echo '</td>
        <td>'; mn_field('text',$MDARTICLE,'Quant','1','6','6','','');
		echo '</td><td>'; mn_field('hselect',$MDARTICLE,'UseTYPE','',"Interno;Externo#1;2",'','','');
		echo '</td><td>'; mn_field('hselect',$MDARTICLE,'Use','',"Interno;Externo#1;2",'','','');
		echo '</td><td>'; mn_field('button',$MDARTICLE,'AddArticle','','','','','insert" onclick="
		document.RequestProperties.action=\'_response/rsproxy.php?act=3&pr=cdc_requests\';
		subform(\'RequestProperties\',\'respRequest\');');
		echo '</td>
		<td></td>
      </tr>';
	  }
   $GETItem = $GLOBALS['MYD']->db_array("SELECT 
	ccenter_requestarticles.ref,
					ccenter_econ.REFER,
					ccenter_requestarticles.ArticleDescription AS Description,
					ccenter_econ.TYPE,
					ccenter_requestarticles.Quantity,
					ccenter_requestarticles.Status,
					ccenter_requestarticles.seTYPE,
					ccenter_requestarticles.se
				FROM ccenter_requestarticles
				LEFT OUTER JOIN ccenter_econ ON ccenter_econ.Ref = ccenter_requestarticles.RefArticle
				WHERE ccenter_requestarticles.RefRequest = {$GET[1]['Ref']}
				AND ccenter_requestarticles.Status != 7"); 
	for ($a = 1; $a <= $GETItem[0]; $a++) {
	   echo '<tr bgcolor="#FFFFFF">
        <td>'.$GETItem[$a]['REFER'].'</td>
        <td>'.$GETItem[$a]['TYPE'].'</td>
        <td>';
		mn_field('text',$MDARTICLE,'Descr'.$GETItem[$a]['ref'],$GETItem[$a]['Description'],'200','50','','');
		echo '</td>
        <td>';
		mn_field('text',$MDARTICLE,'Quant'.$GETItem[$a]['ref'],round($GETItem[$a]['Quantity']),'6','6','','');
		echo '</td>
        <td>';
		$Qur = "Interno;Externo#1;2";
		mn_field('hselect',$MDARTICLE,'UseTYPE'.$GETItem[$a]['ref'],$GETItem[$a]['seTYPE'],$Qur,'','','');
		echo '</td>
        <td>';
		$Qur = "Interno;Externo#1;2";
		mn_field('hselect',$MDARTICLE,'Use'.$GETItem[$a]['ref'],$GETItem[$a]['se'],$Qur,'','','');
		echo '</td>
        <td>';
	$Qur = "SELECT Ref AS ID, name AS NAME FROM hcce_status WHERE Type = 0";
	mn_field('select','ED','Status',$GETItem[$a]['Status'],$Qur,'','','');
		echo '</td>
		<td>';
	if($GET[1]['Ref'] == 0) { 
		mn_field('button',$MDARTICLE,'Save','Alterar','','','','" 
	onClick="document.RequestProperties.ArticleID.value='.$GETItem[$a]['ref'].';
				document.RequestProperties.ArticleStatus.value=document.RequestProperties.Status'.$GETItem[$a]['ref'].'.value;
				document.RequestProperties.ArticleQuant.value=document.RequestProperties.Quant'.$GETItem[$a]['ref'].'.value;
				document.RequestProperties.ArticleUse.value=document.RequestProperties.Use'.$GETItem[$a]['ref'].'.value;
				document.RequestProperties.ArticleUseTYPE.value=document.RequestProperties.UseTYPE'.$GETItem[$a]['ref'].'.value;
				document.RequestProperties.ArticleDescr.value=document.RequestProperties.Descr'.$GETItem[$a]['ref'].'.value;
				document.RequestProperties.submit();');
		}
		echo '</td>
      </tr>';
	  } ?>
    </table>